package com.ziqikeji.thread;

/**
 * 设计一个程序，启动三个线程A,B,C,各个线程只打印特定的字母，各打印5次，例如A线程只打印‘A’。要求在控制台依次显示“ABCABC…”
 * <p>
 * Created by Admin on 2018/8/8.
 */
public class WaitNotifyThree {
    private static int resource = 0;
    private final static Object lock = new Object();


    public static void main(String[] args) {
        Thread threadOne = new Thread(){
            public void run(){
                WaitNotifyThree.calc("A");
            }
        };
        Thread threadTwo = new Thread(){
            public void run(){
                WaitNotifyThree.calc("B");
            }
        };
        Thread threadThree = new Thread(){
            public void run(){
                WaitNotifyThree.calc("C");
            }
        };

        threadOne.start();
        threadTwo.start();
        threadThree.start();
    }
    //synchronized 同步关键字方法
    private  static void calc(String num){
        synchronized (lock) {
            resource = ++resource;
            System.out.println(num+":"+ resource);
        }
    }
}
